# Maintainer: Martell Malone <martellmalone@gmail.com>
# Contributor: Biswapriyo Nath <nathbappai@gmail.com>

_realname=wslay
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.1
pkgrel=1
pkgdesc="The WebSocket library in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/tatsuhiro-t/wslay"
license=("custom")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cunit"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-nettle"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/tatsuhiro-t/wslay/archive/release-${pkgver}.tar.gz")
sha256sums=('7b9f4b9df09adaa6e07ec309b68ab376c0db2cfd916613023b52a47adfda224a')

prepare() {
  cd "${srcdir}/${_realname}-release-${pkgver}"
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-release-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  # WARNING: Dirty hack due to absence of conf.py in source directory.
  #          As it is required by python-sphinx to build man pages.

  cp "${srcdir}/build-${MINGW_CHOST}/doc/sphinx/conf.py" \
  "${srcdir}/${_realname}-release-${pkgver}/doc/sphinx/conf.py"

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
